package br.edu.ifpi.aula0204.collections.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionFactory {

	private static ConnectionFactory instance = new ConnectionFactory();
	private Connection connection;

	private ConnectionFactory() {
	}

	private Connection createConnection() {
		try {
			if (connection == null) {
				connection = DriverManager
						.getConnection("jdbc:mysql://127.0.0.1:3306/eventos",
								"root", "igu4l");
			}
			return connection;
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	public static Connection getConnection() {
		return instance.createConnection();
	}

}
